#!/usr/bin/env bash

if [ -e buildSrc ]; then
  echo "buildSrc dir exists, do nothing"
  exit 0
fi

mkdir -p buildSrc/src/main/java
mkdir -p buildSrc/src/main/kotlin
mkdir -p buildSrc/src/test/java

cat << EOF >buildSrc/build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.jvm").version("1.3.61")
    // 方便使用kotlin开发构建逻辑：
    // https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin
    \`kotlin-dsl\`
}

repositories {
    maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
    maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
    maven { setUrl("https://maven.aliyun.com/repository/public") }
    maven { setUrl("https://maven.aliyun.com/repository/central") }
    mavenCentral()
}

dependencies {
    testImplementation("junit:junit:4.13")
}

EOF

cat <<EOF >buildSrc/src/main/kotlin/MavenRepoMgr.kt

import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.maven

object MavenRepoMgr {

    const val GradlePlugin = "https://maven.aliyun.com/repository/gradle-plugin"
    const val JCenter = "https://maven.aliyun.com/repository/jcenter"
    const val Google = "https://maven.aliyun.com/repository/google"
    const val Maven = "https://maven.aliyun.com/repository/public"
    const val Center = "https://maven.aliyun.com/repository/central"

    fun applyAll(repoHandler: RepositoryHandler) {
        repoHandler.maven(GradlePlugin)
        repoHandler.maven(JCenter)
        repoHandler.maven(Google)
        repoHandler.maven(Maven)
        repoHandler.maven(Center)
        //        google()
        //        jcenter()
        //        mavenCentral()
    }
}

EOF


echo "Create Success!!!"

#grep -n 'repositories ' ./settings.gradle.kts | cut -d : -f 1
